const { _electron: electron } = require("playwright");
const { stubDialog } = require("electron-playwright-helpers");
const path = require("path");

async function testClickLicense() {
    const electronApp = await electron.launch({
        executablePath: "C:\\Program Files\\Max-Optics\\MaxOpticsStudio\\2025R1\\v3.3.3.0_09100454\\gui\\mos\\MaxOpticsStudio.exe",
    });
    let page;
    // 获取最后一个窗口
    for (const window of electronApp.windows()) {
        const url = window.url();
        if (url.includes("resources/static/index")) {
            page = window;
            break;
        }
    }

    // 获取New按钮
    let newElement = page.locator(".iconfont.icon-New");
    await newElement.click();

    // 拦截系统对话框，保存到当前目录，名字为test.mop
    await stubDialog(electronApp, "showSaveDialog", {
        filePath: path.join(__dirname, `./test.mop`),
    });

    // 等待10秒去保存
    await page.waitForTimeout(10000);

    // 保存
    let saveElement = page.locator(".iconfont.icon-Save");
    await saveElement.click();
}

testClickLicense();
